<template>
    <div>
      
        <el-card>
            <div class="table">
                <el-table :data="tableData" strip>

                    <el-table-column label="序号" type="index" align="center" sortable>
                         
                    </el-table-column>
                    <el-table-column prop="orderId" label="订单编号" >
                      

                    </el-table-column>

                    <el-table-column prop="createTime" label="下单时间"></el-table-column>
                    <el-table-column prop="totalPrice" label="总价">
                          <template v-slot="scopes">
                            <div style="color: red; font-weight: bold;">￥{{ scopes.row.totalPrice }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column prop="status" label="状态"></el-table-column>
                      <el-table-column prop="userName" label="下单人"></el-table-column>
                    <el-table-column label="操作" align="center" width="180" fixed="right">
                        <template v-slot="scope">
                            <el-button size="mini" v-if="scope.row.status== '待发货'" type="primary" plain @click="del(scope.row.id)">发货</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div class="pagination" style="margin-top: 10px;">
                    <el-pagination background @current-change="handleCurrentChange" :current-page="queryform.pageNum"
                        :page-sizes="[5, 10, 20]" :page-size="queryform.pageSize" layout="total, prev, pager, next"
                        :total="total">
                    </el-pagination>
                </div>
            </div>

        </el-card>
       
    </div>
</template>
<script>
import service from '@/request';

export default {
    data() {
        return {
            tableData: [],  // 所有的数据
            pageNum: 1,   // 当前的页码
            pageSize: 10,  // 每页显示的个数
            total: 0,
            username: null,
            img: "",
            token: "",
            fileList: [],
            name: null,
            uploadHeaders: {

                Authorization: window.localStorage.getItem("token")
            },

            fromVisible: false,
            avatar: "",
            queryform: {
                keyword: "",
                pageNum: 1,
                pageSize: 10
            },
            license: "",
            form: {
                img: "",

            },
            user: {},
            rules: {

                icon: [
                    { required: true, message: '请输入名称', trigger: 'blur' },
                ],
                name: [
                    { required: true, message: '请输入名称', trigger: 'blur' },
                ],
                remark: [
                    { required: true, message: '请输入名称', trigger: 'blur' },
                ],

                // business_id: [
                //     { required: true, message: '请选择商家类型', trigger: 'blur' },
                // ]
            },
            ids: [],
            sjlist: [],
        }
    },
    mounted() {
        this.token = window.localStorage.getItem("token")
        this.user = JSON.parse(window.localStorage.getItem("userinfo"))
        console.log(this.user)

        this.getlist()
    },
    methods: {


        del(id) {
            this.$confirm('是否确认发货?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                const res = await service.get("/order/fh?id=" + id)
                console.log(res)
                if (res.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '发货成功!'
                    });
                    this.getlist()
                }

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        force(e) {
            this.form.timeRange = e;
            this.$forceUpdate();
        },
        handleEdit(row) {
            this.form = row;
            this.img = row.img;


            this.fromVisible = true
        },
        search() {
            this.queryform.pageNum = 1;
            this.queryform.pageSize = 10;
            this.getlist()
        },
        research() {
            this.queryform.keyword = ""
            this.queryform.pageNum = 1;
            this.queryform.pageSize = 10;
            this.getlist()

        },
        async getlist() {
            // if (this.user.role == 'HOTEL') {
            //     this.queryform.hotelId = this.user.id

            // }else{
            //     this.queryform.hotelId = ""

            // }
            const res = await service.get("/order/sjlist", { params: this.queryform });
            console.log(res);
            if (res.code == 200) {
                this.tableData = res.data.records;
                this.total = res.data.total;
            }


        },
        add() {
            this.img = ""
            this.form = {}

            this.fromVisible = true

        },
        handleLicenseSuccess(e) {

        },
        async save() {
            if (!this.form.icon) {
                this.$message.warning("请上传图片")
            }
            if (!this.form.name) {
                this.$message.warning("请上传图片")
            }
            if (!this.form.remark) {
                this.$message.warning("请上传图片")
            }
            const res = await service.post("/type/addorupdate", this.form);
            if (res.code == 200) {
                this.fromVisible = false
                this.$message.success("操作成功")
                this.getlist()
            }





        },
        handleCurrentChange(e) {

        },
        handleAvatarSuccess(e) {
            console.log(e)

            this.form.icon = e.data;
            this.$forceUpdate()
            // this.fileList.push({

            // })

        },

    }
}
</script>
<style scoped>
.mb {
    margin-bottom: 10px;
}
</style>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px !important;
    text-align: center;
}

.avatar {
    width: 178px;
    height: 178px;
    display: block;
}
</style>